package com.uhomecp.lambda.time7;

import java.time.*;

public class Java8Tester {
    public static void main(String[] args) {
        Java8Tester java8tester = new Java8Tester();
        java8tester.testLocalDateTime();

        //获取时区的时间
        java8tester.testZonedDateTime();
    }

    public void testLocalDateTime(){
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("当前时间："+localDateTime);

        LocalDate localDate = localDateTime.toLocalDate();
        System.out.println("当前时间:"+localDate);

        Month month = localDateTime.getMonth();
        int dayOfMonth = localDateTime.getDayOfMonth();
        int second = localDateTime.getSecond();
        System.out.println("month:" + month.getValue() + "-"+ " day:" + dayOfMonth + " second:" + second);

        LocalDateTime localDateTime1 = localDateTime.withDayOfMonth(10).withYear(2012);
        System.out.println("localDateTime1:"+localDateTime1);

        LocalDate of = LocalDate.of(2014, Month.DECEMBER, 12);
        System.out.println("of:"+of);

        LocalTime of1 = LocalTime.of(20, 15);
        System.out.println("of1:"+of1);

        LocalTime parse = LocalTime.parse("23:23:12");
        System.out.println("parse:"+parse);
    }

    public void testZonedDateTime(){

        // 获取当前时间日期
        ZonedDateTime date1 = ZonedDateTime.parse("2015-12-03T10:15:30+05:30[Asia/Hong_Kong]");
        System.out.println("date1: " + date1);

        ZoneId id = ZoneId.of("Europe/Paris");
        System.out.println("ZoneId: " + id);

        ZoneId currentZone = ZoneId.systemDefault();
        System.out.println("当期时区: " + currentZone);
    }
}
